package com.xiaol.websocketstomp.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.messaging.simp.user.SimpUserRegistry;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * User: Ray.Shaw <p />
 * Time: 2018/8/1 10:32  <p />
 * Version: V1.0  <p />
 * Description:  <p />
 */
@RestController
@RequestMapping(path = "rest")
public class TestController {
    @Autowired
    public SimpMessagingTemplate template;

    @Autowired
    private SimpUserRegistry userRegistry;

    @GetMapping("hel/{destination}/{content}")
    public String y(@PathVariable String destination, @PathVariable String content) {
        template.convertAndSend("/topic/getResponse" + "/" + destination, content);
        return "xl";
    }

    @GetMapping("hel1/{content}")
    public String yx(@PathVariable String content) {
        template.convertAndSend("/topic/greetings", content);
        return "xl";
    }

    @GetMapping("user-num")
    public String yxz() {
        String xx ="当前在线人数:" + Integer.toString(userRegistry.getUserCount());
        return xx;
    }
}
